//切换城市行政区事件
$("#city").bind("change", function(){
    $("#district option").remove();
    $("#s2id_district span:first").html("行政区");
    var city = $("#city").val()
    $("#district").append("<option value='-1' >行政区</option>")
    if(city=='-1'){
        return
    }
    $.ajax({
        url: "/estate/districtList",
        type: "POST",
        data: {'city': city} ,
        success: function(result){
            for(var i=0; i < result.districtList.length; i++){
                $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
            }
        }
    });
});
//切换行政区片区
$("#district").bind("change", function(){
    $("#precinct option").remove();
    $("#s2id_precinct span:first").html("片区");
    var district = $("#district").val();
    $("#precinct").append("<option value='-1' >片区</option>");
    if(district=='-1'){
        return
    }
    $.ajax({
        url: " ",
        type: "POST",
        data: {'district': district} ,
        success: function(result){

        }
    });
});
//切换城市地图事件
function search(){
    //清空搜索
    $("#search").val("");
    $('#searchCommunity').html("");
    $('#searchCommunity').css('display','none');
    $('#district').val("");
    $("#s2id_district span:first").html("行政区");
    $('#precinct').val("");
    $("#s2id_precinct span:first").html("片区");
    var zoneNumber = $("#city").val();
    var cityName = $("#city").find("option:selected").text();
    scrollFlag = false;
    map.clearOverlays();
    if(zoneNumber == "-1"){
        map.setMinZoom(6);
        map.disableScrollWheelZoom();
        map.centerAndZoom(new BMap.Point(106.530635013,29.5446061089),6);
        initMap(aroundAccountUrl,{currentMap:currentMap,city:zoneNumber,level:"1"});
    }else if(zoneNumber && zoneNumber!='-1'){
        map.setMinZoom(13);
        map.centerAndZoom(cityName,13);
        RequestData (aroundAccountUrl,{city:zoneNumber,level:"3"});
        createDeveloperDistrict(allMapData);
    }


}
//参数改变事件
function searchData(map){//搜索条件改变事件
    $('#searchCommunity').css('max-height','400px');
    var inputData = getInputData();
    map.clearOverlays();
    RequestData(accountCommunityUrl,inputData);
    if(allMapData.length==0 || mapDataStatus==false){
        $('#searchAccount').css('display','none');
        return
    }
    scrollFlag=false;
    map.centerAndZoom(new BMap.Point(allMapData[0].lng, allMapData[0].lat),16);
    searchAccountResult("searchCommunity",allMapData);
    createDeveloper(allMapData);
}
//网点搜索结果HTML
function searchAccountResult(id,paramsData){
    $('#'+id+'').css('display','block');
    var html='';
    $.each(paramsData,function(i,obj){
        var accountName = obj.accountName;
        var count = obj.count;
        var href = obj.accountId;
        html+=
            "<li><h5>"+(i+1)+"</h5><div><a class='linkMap' id='"+obj.accountId+"'>"+accountName+"</a><p>地址："+obj.address+"</p></div></li>";
    });
    $('#'+id+'').html(html);
    $('#'+id+' li').addClass('list-group-item media social-profile clearfix p-b-n');
    $('#'+id+' li h5').addClass('pull-left text-center p-n m-n');
    $('#'+id+' li div').addClass('media-body ');
    // 点击网点进入楼栋
    $(".linkMap").click(function(){
        var href = window.location.origin + "/estate/searchEstate?accountId=" + this.id;
        window.open(href);
    })
}
//页面参数
function getInputData(){
    var accountName=$("#search").val(),
        city=$('#city').val(),
        district=$('#district').val(),
        precinct=$('#precinct').val(),
        inputData={
            accountName:accountName,
            city:city,
            district:district,
            precinct:precinct
        };
    return inputData;
}